import json
import requests
def qianfan_chat(token, content, length=30):
    if not token:
        return "请重新设置百度千帆模型初始化模块"
    if not content:
        return "内容识别为空"
    url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=" + token
    payload = json.dumps({"messages": [{"role": "user", "content": f"{content} 限{length}字以内"}]})
    headers = {
        'Content-Type': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    print(response.text)
    res = response.json()
    if res and res.get("result"):
        return res.get("result")
    return "我还没想好你的问题"
